package com.twu.biblioteca;


import com.twu.biblioteca.commands.Command;
import com.twu.biblioteca.domain.Book;

import java.util.ArrayList;
import java.util.List;

import static java.util.Arrays.asList;

public class Biblioteca {
    private List<String> menueList;
    private String message;
    private Command command;
    private List<Book> books = new ArrayList<Book>();

    Biblioteca() {

        books.add(new Book("TDD", "1"));
        books.add(new Book("Refactor", "2"));

    }

    public void start() {
        menueList = new ArrayList<String>(asList("List the books", "Reserve bookId", "Check membership"));
        message = "Welcome to Biblioteca!";
    }

    public String showMenuList() {
        String menuString = "";
        if (menueList.size() > 0) {
            for (String menu : menueList) {
                menuString += menu;
                menuString += "\n";
            }
            menuString += "Please input the menuString or q to exit the system:";
        }
        return menuString;
    }

    public String showMessage() {

        return message;
    }

    public void executeCommand(String s) {
        this.command = Command.createCommad(s);
        if (command != null)
            this.message = command.execute(books);
        else this.message = "Invalied option!";
    }

    public void setBooks(List<Book> books) {
        this.books = books;
    }
}
